package logic

import (
	"context"
	"sport/models/mysql"

	"sport/sportrpc/internal/svc"
	"sport/sportrpc/sportrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type PostAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPostAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PostAddLogic {
	return &PostAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 帖子发布
func (l *PostAddLogic) PostAdd(in *sportrpc.PostAddRequest) (*sportrpc.PostAddResponse, error) {
	// todo: add your logic here and delete this line
	post := mysql.Post{
		UserId:  int(in.UserId),
		Title:   in.Title,
		Content: in.Content,
		Liked:   int(in.Liked),
	}
	mysql.DB.Create(&post)
	return &sportrpc.PostAddResponse{
		Id: int64(post.ID),
	}, nil
}
